package com.ruoyi.service.project.service.impl;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.common.core.enums.YesNoEnum;
import com.ruoyi.service.project.entity.ProjectSuddenEntity;
import com.ruoyi.service.project.mapper.ProjectSuddenMapper;
import com.ruoyi.service.project.service.ProjectSuddenService;
import java.util.List;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 项目异常管理 服务实现类
 * </p>
 *
 * @author Zane
 * @since 2025-10-17
 */
@Service
public class ProjectSuddenServiceImpl extends ServiceImpl<ProjectSuddenMapper, ProjectSuddenEntity>
    implements ProjectSuddenService {

  @Override
  public List<ProjectSuddenEntity> listByProjectId(String projectId) {
    return list(effectQuery().eq(ProjectSuddenEntity::getProjectId, projectId)
        .orderByDesc(ProjectSuddenEntity::getId));
  }

  @Override
  public Long projectDemanderSuddenCount(Long userId) {
    return count(effectQuery().eq(ProjectSuddenEntity::getProjectCreator, userId));
  }

  private LambdaQueryWrapper<ProjectSuddenEntity> effectQuery() {
    return new LambdaQueryWrapper<ProjectSuddenEntity>()
        .eq(ProjectSuddenEntity::getDeleteFlag, YesNoEnum.NO.getCode());
  }
}
